/*
 * BanBu_DetailCell
 * @description 本文件提供广播详情界面回复人的定制cell
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供广播详情界面回复人的定制cell
 */

#import "BanBu_DetailCell.h"
#import "BanBu_PersonDataViewController.h"
@implementation BanBu_DetailCell

- (void)dealloc
{
    _lineView = nil;
    self.selectPeopleCallBack = nil;
    _iconButton = nil;
    _nameLabel = nil;
    _distanceAndTimeLabel = nil;
    _lastTimeLabel = nil;
    _sayTextLabel = nil;
    _playButton = nil;
    _timeLabel = nil;
    _replyNameLabel = nil;
    [super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _lineView = [[UIView alloc] init];
        
        _lineView.backgroundColor = [UIColor colorWithRed:224.0/255 green:224.0/255 blue:224.0/255 alpha:1.0];
        [self.contentView addSubview:_lineView];
        [_lineView release];
        
        //头像
        _iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _iconButton.frame = CGRectMake(10, 10, 35, 35);
        
        //        _iconButton.layer.borderColor = [[UIColor blackColor]CGColor];
        //        _iconButton.layer.borderWidth = 1.0;
        _iconButton.layer.cornerRadius = 17.5;
        _iconButton.layer.masksToBounds = YES;
        [_iconButton addTarget:self action:@selector(pushProfile:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:_iconButton];
        
        //名字
        _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(55, 10, 180, 17)];
        _nameLabel.backgroundColor = [UIColor clearColor];
        //        _nameLabel.text = @"Yumi Lai and 张三";
        _nameLabel.font = [UIFont boldSystemFontOfSize:13];
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.numberOfLines = 0;
        [self.contentView addSubview:_nameLabel];
        [_nameLabel release];
        
        //回复时间
        _lastTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(215, 10, 75, 17)];
        _lastTimeLabel.backgroundColor = [UIColor clearColor];
        //        _lastTimeLabel.text = @"1天前";
        _lastTimeLabel.textAlignment = kTextAlignmentRight;
        _lastTimeLabel.font = [UIFont boldSystemFontOfSize:13];
        _lastTimeLabel.textColor = [UIColor lightGrayColor];
        [self.contentView addSubview:_lastTimeLabel];
        [_lastTimeLabel release];
        
        //文字（可选）
        _sayTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(55, 27, 255, 17)];
        _sayTextLabel.textColor = [UIColor blackColor];
        _sayTextLabel.font = [UIFont systemFontOfSize:13];
        _sayTextLabel.backgroundColor = [UIColor clearColor];
        
        //        _sayTextLabel.frame = CGRectMake(55, 44+10, 235, textLabelHeight);
        _sayTextLabel.numberOfLines = 0;
        [self.contentView addSubview:_sayTextLabel];
        [_sayTextLabel release];
        
        //@谁。。
        //        _replyNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 80, 17)];
        _replyNameLabel = [[UILabel alloc] init];
        _replyNameLabel.numberOfLines = 1;
        _replyNameLabel.lineBreakMode = kTextLineBreakByTruncatingMiddle;
        _replyNameLabel.textColor = [UIColor blueColor];
        _replyNameLabel.font = [UIFont systemFontOfSize:13];
        _replyNameLabel.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_replyNameLabel];
        _sayTextLabel.userInteractionEnabled = YES;
        _replyNameLabel.userInteractionEnabled = YES;
        [_replyNameLabel release];
        
        UITapGestureRecognizer *replyPress = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(seeProfile:)];
        [_replyNameLabel addGestureRecognizer:replyPress];
        
        //播放按钮(可选)
        _playButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _playButton.hidden = YES;
        [_playButton setImage:[UIImage imageNamed:@"playButton.png"] forState:UIControlStateNormal];
        [_playButton setImage:[UIImage imageNamed:@"广播详情-复选框-播放.png"] forState:UIControlStateHighlighted];
        [_playButton addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_playButton];
        
        
        _timeLabel = [[UILabel alloc]initWithFrame:CGRectZero];
        _timeLabel.backgroundColor = [UIColor clearColor];
        _timeLabel.textColor = [UIColor whiteColor];
        _timeLabel.font = [UIFont systemFontOfSize:14];
        _timeLabel.textAlignment= kTextAlignmentRight;
        [self.contentView addSubview:_timeLabel];
        [_timeLabel release];
        
    }
    return self;
}
-(void)seeProfile:(UITapGestureRecognizer *)_tap
{
    
    NSDictionary *aDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%d",_tap.view.tag/22],@"userid",[NSArray array],@"facelist",nil];
    BanBu_PersonDataViewController *peopleFfofile = [[BanBu_PersonDataViewController alloc] initWithProfile:aDic];
    peopleFfofile.hidesBottomBarWhenPushed = YES;
    UITableView *tableView = (UITableView *)self.superview;
    if(![tableView isKindOfClass:[UITableView class]])
    {
        tableView = (UITableView *)tableView.superview;
    }
    id next = [self nextResponder];
    while(![next isKindOfClass:[UIViewController class]])//这里跳不出来。。。
    {
        next = [next nextResponder];
    }
    [((UIViewController *)next).navigationController pushViewController:peopleFfofile animated:YES];
    [peopleFfofile release];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void)setAvatar:(NSString *)avatarUrlStr{
    
    [_iconButton setImageWithURL:[NSURL URLWithString:avatarUrlStr] placeholderImage:[UIImage imageNamed:@"default.png"] andType:1];
    
}

-(void)pushProfile:(UIButton *)sender{
    if (_selectPeopleCallBack)
    {
        _selectPeopleCallBack(sender.tag);
    }
}
-(void)play:(UIButton *)sender{
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"playVoice" object:sender];
}

-(void)setSaytext:(NSDictionary *)_content
{
    
    if([[_content valueForKey:@"topname"] length])
    {
        _replyNameLabel.text = [NSString stringWithFormat:@"RE @%@: ",[_content valueForKey:@"topname"]];
        if(_replyNameLabel.text.length >18)
        {
            _replyNameLabel.text = [NSString stringWithFormat:@"RE @%@: ",[[_content valueForKey:@"topname"] substringToIndex:13]];
        }
        float replyNameWidth = [_replyNameLabel.text sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 17) lineBreakMode:NSLineBreakByTruncatingMiddle].width;
        _replyNameLabel.frame = CGRectMake(55, 27, replyNameWidth, 17);
        _replyNameLabel.tag = [[_content valueForKey:@"touid"] integerValue]*22;
    }
    else
    {
        _replyNameLabel.tag   = 0;
        _replyNameLabel.frame = CGRectZero;
        _replyNameLabel.text = @"";
    }
    
    
    NSString *sayText = [NSString stringWithFormat:@"%@%@",_replyNameLabel.text,[_content valueForKey:@"saytext"]];
    _sayTextLabel.text = sayText;
    float textLabelHeight = [sayText sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(235, 100) lineBreakMode:kTextLineBreakByWordWrapping].height;
    _sayTextLabel.frame = CGRectMake(55, 27, 235, textLabelHeight);
    
    
    if([sayText length])
        [_lineView setFrame:CGRectMake(0, 38+textLabelHeight-1, 320, 1.0)];
    else
        [_lineView setFrame:CGRectMake(0, 54, 320, 1.0)];
    
    
}
//-(void)setSaytext:(NSString *)_sayText
//{
//    _sayTextLabel.text = _sayText;
//    float textLabelHeight = [_sayText sizeWithFont:[UIFont boldSystemFontOfSize:13] constrainedToSize:CGSizeMake(235, 100) lineBreakMode:kTextLineBreakByWordWrapping].height;
//    _sayTextLabel.frame = CGRectMake(55, 27, 255, textLabelHeight);
//
////    WithFrame:
//    if(_sayText.length)
//    [_lineView setFrame:CGRectMake(0, 38+textLabelHeight-1, 320, 1.0)];
//    else
//        [_lineView setFrame:CGRectMake(0, 54, 320, 1.0)];
//
//
//}
@end
